/**
 * Created by Administrator on 2016/9/5.
 */
    /*显示申请框*/
$('.get-free').on('touchstart',function(){
    $('#background').removeClass('hide')
    $('#phone').focus();
})
/*关闭申请框*/
$('.m-cloes').on('click',function(){
    $('#background').addClass('hide')
})
/*获取验证码*/
function getCode(e){
    var mobile = $('#phone').val();
    var isPhone = checkPhone(mobile); //验证手机号码
    if(isPhone){
        $.getJSON("/buildings/front/building/ajaxSendCode", {mobile:mobile, building_code:'lingxi'}, function(logJson) {
            if (logJson.status == 'ok') {
                alert("验证码发送成功");
                resetCode(); //倒计时
            }else{
                $('#phone').focus();
                alert(logJson.status);
            }
        });
    }else{
        $('#phone').focus();
    }
}
//验证手机号码
function checkPhone(phone){
    var pattern = /^1[34578]\d{9}$/;
    var isPhone = 1;
    if(phone == '') {
        alert('请输入手机号码');
        isPhone = 0;
    }else if(!pattern.test(phone)){
        alert('请输入正确的手机号码');
        isPhone = 0;
    }
    return isPhone;
}
//倒计时
function resetCode(){
    $('#J_getCode').hide();
    $('#J_second').html('60');
    $('#J_resetCode').show();
    var second = 60;
    var timer = null;
    timer = setInterval(function(){
        second -= 1;
        if(second >0 ){
            $('#J_second').html(second);
        }else{
            clearInterval(timer);
            $('#J_getCode').show();
            $('#J_resetCode').hide();
        }
    },1000);
}